﻿<common:LayoutAwarePage
    x:Name="pageRoot"
    x:Class="GSBA.Views.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:controls="using:GSBA.Controls"
    xmlns:vm="using:GSBA.ViewModels"
    xmlns:common="using:GSBA.Common"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d" NavigationCacheMode="Enabled" Height="Auto">

    <UserControl.Resources>

        <!-- Converters -->
        <common:BooleanToVisibilityConverter x:Key="BooleanToVisiblityConverter"/>

        <!-- View collection -->
        <CollectionViewSource
            x:Name="groupedItemsViewSource"
            Source="{Binding Items}"
            IsSourceGrouped="true"
            d:Source="{Binding Items, Source={d:DesignInstance Type=vm:MainPageViewModel, IsDesignTimeCreatable=True}}"
        />
    </UserControl.Resources>

    <Grid x:Name="BaseGrid" Style="{StaticResource BasePageStyle}">
        <Grid>

            <!-- The base layout is 2 row grid, title and tiles -->
            <Grid.RowDefinitions>
                <RowDefinition Height="150"></RowDefinition>
                <RowDefinition Height="*"></RowDefinition>
            </Grid.RowDefinitions>

            <!-- Title -->
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <!--<Button x:Name="backButton" IsEnabled="False" Style="{StaticResource BackButtonStyle}"/>-->
                <Image x:Name="LogoImage" Source="/Assets/Logo.png" Width="60" Height="60" Margin="36,0,36,36" VerticalAlignment="Bottom"/>
                <TextBlock x:Name="pageTitle" Text="{StaticResource MainTitle}" Grid.Column="1" Style="{StaticResource PageHeaderTextStyle}"/>
            </Grid>

            <!-- Grid view for tiles -->
            <StackPanel Grid.Row="1" Visibility="{Binding IsCategoryLoading, Converter={StaticResource BooleanToVisiblityConverter}}" VerticalAlignment="Center">
                <ProgressRing Foreground="{StaticResource SelectedListViewItemColor}" IsActive="True" HorizontalAlignment="Center" Width="120" Height="120"></ProgressRing>
            </StackPanel>

            <GridView 
                x:Name="TilesGridView"
                Visibility="{Binding IsCategoryLoadingCompleted, Converter={StaticResource BooleanToVisiblityConverter}}"
                ItemTemplate="{StaticResource CustomTileSmallItem}" 
                Padding="130,0,130,0" 
                Grid.Row="1"
                ItemsSource="{Binding Items}" 
                ItemClick="TileGrid_ItemClick"
                IsItemClickEnabled="True"
                SelectedItem="{Binding SelectedCategory}"
                SelectionMode="None"
                ScrollViewer.IsHorizontalScrollChainingEnabled="False" 
                ItemContainerStyle="{StaticResource NavigationGridViewItemStyle}">


            </GridView>
        </Grid>

        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="ApplicationViewStates">
                <VisualState x:Name="FullScreenLandscape">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="LogoImage" Storyboard.TargetProperty="(UIElement.Visibility)">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible">
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
                <VisualState x:Name="Filled">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="LogoImage" Storyboard.TargetProperty="(UIElement.Visibility)">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible">
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
                <VisualState x:Name="Snapped">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(Control.Padding)" Storyboard.TargetName="TilesGridView">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Thickness>10,0,130,0</Thickness>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                       
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="LogoImage" Storyboard.TargetProperty="(UIElement.Visibility)">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed">
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>

                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="pageTitle" Storyboard.TargetProperty="(Control.Padding)">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Thickness>10,0,0,0</Thickness>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</common:LayoutAwarePage>
